//
//  SharedExample+Activity.swift
//  SwiftCode
//
//  Created by yuhus on 2023/10/17.
//

import Foundation
import UIKit

extension UIActivity.ActivityType: CaseIterable {
  /// "com.apple.reminders.RemindersEditorExtension"
  /// "com.apple.mobilenotes.SharingExtension"
  /// "com.apple.mobileslideshow.StreamShareService"
  public static var allCases: [UIActivity.ActivityType] {
    return [
      .postToFacebook,
      .postToTwitter,
      .postToWeibo,
      .message,
      .mail,
      .print,
      .copyToPasteboard,
      .assignToContact,
      .saveToCameraRoll,
      .addToReadingList,
      .postToFlickr,
      .postToVimeo,
      .postToTencentWeibo,
      .airDrop,
      .openInIBooks,
      .markupAsPDF,
      UIActivity.ActivityType(rawValue: "com.apple.mobilenotes.SharingExtension")]
  }
}

final class CustomActicity: UIActivity {
  override var activityType: UIActivity.ActivityType? {
    return ActivityType(rawValue: "CustomActicity")
  }
  
  override var activityTitle: String? {
    return "GPark"
  }
  
  override var activityImage: UIImage? {
    return UIImage.init(named: "shareIcon")
  }
  
  override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
    return true
  }
  
  override func prepare(withActivityItems activityItems: [Any]) {
    print(#function, "🔴")
    print(activityItems)
  }
  
  override class var activityCategory: UIActivity.Category {
    return Category.share
  }
  
  override func perform() {
    print(#function, "🔴")
    activityDidFinish(true)
  }
}
